#include "stdio.h"
#include "string.h"
#include "ProtocolAPI.h"
#include "dhstruct.h"

 

int GettotalResolution(int height,char *Resolution[])
{
	int i = 0;
	switch(height)
	{
		case 1520:
			Resolution[i++] = (char*)"4M";
		case 1296:
		case 1536:
			Resolution[i++] = (char*)"3M";
		case 1080:
			Resolution[i++] = (char*)"1080P";
		case 960:
			Resolution[i++] = (char*)"1_3M";
		case 720:
			Resolution[i++] = (char*)"720P";
		case 576:
			Resolution[i++] = (char*)"D1";
		case 480:
			Resolution[i++] = (char*)"VGA";
		case 288:
			Resolution[i++] = (char*)"CIF";
		case 240:
			Resolution[i++] = (char*)"QVGA";
			break;
		default:
			printf("unknown ResolutionMask,need to be supported!\n");
			break;
	} 
	return i;
}




int GetResolutionMask(int height,int stream)
{
	int Resolution = 0xffffffff;
	int ResolutionMask = 0;
	switch(height)
	{
		case 1920:
			if(stream == 0)
				ResolutionMask |= Resolution&(1<<CAPTURE_SIZE_5M);//17 14 12 11 5 0
		case 1520:
			if(stream == 0)
				ResolutionMask |= Resolution&(1<<CAPTURE_SIZE_NR);//17 14 12 11 5 0
		case 1296:
		case 1536:
			if(stream == 0)
				ResolutionMask |= Resolution&(1<<CAPTURE_SIZE_3M);//17 14 12 11 5 0
		case 1080:
			if(stream == 0)
				ResolutionMask |= Resolution&(1<<CAPTURE_SIZE_1080p);
		case 960:
			if(stream == 0)
				ResolutionMask |= Resolution&(1<<CAPTURE_SIZE_1_3M);
		case 720:
			if(stream == 0)
				ResolutionMask |= Resolution&(1<<CAPTURE_SIZE_720p);
		case 576:
			if((height > 576)||((height == 576)&&(stream == 0)))
				ResolutionMask |= Resolution&(1<<CAPTURE_SIZE_D1);
		case 480:
			if((height > 480)||((height == 480)&&(stream == 0)))
				ResolutionMask |= Resolution&(1<<CAPTURE_SIZE_VGA);
			if((height >= 480)&&(stream == 0))
				break;
		case 288:
			ResolutionMask |= Resolution&(1<<CAPTURE_SIZE_CIF);
		case 240:
			ResolutionMask |= Resolution&(1<<CAPTURE_SIZE_QVGA);
			break;
		default:
			printf("unknown ResolutionMask,need to be supported!\n");
			break;
	} 
	return ResolutionMask;
}


typedef struct _DHReslutionInfo_T{
	int res;
	int width;
	int height;
	char *name;
}DHReslutionInfo_T;
//	char const *Resolution_size[] = {"QCIF","CIF", "D1", "720P", "960P", "1080P","2M", "3M", "4M", "5M", "5M"};
static DHReslutionInfo_T resolutionDef[] = {
	
	{CAPTURE_SIZE_D1,704,576,	"D1"},
	{CAPTURE_SIZE_HD1,352,576,	"D1"},
	{CAPTURE_SIZE_BCIF,704,288,	"D1"},
	{CAPTURE_SIZE_CIF,352,288,	"CIF"},
	{CAPTURE_SIZE_QCIF,176,144,	"QCIF"},
	{CAPTURE_SIZE_VGA,640,480,	 "VGA"},
	{CAPTURE_SIZE_QVGA,320,240,	 "QVGA"},	
	{CAPTURE_SIZE_SVCD,480,480,	 "SVCD"},
	{CAPTURE_SIZE_SVCD,320,240,	 "SVCD"},
	{CAPTURE_SIZE_QQVGA,160,128, "QQVGA"},
	{CAPTURE_SIZE_SVGA,800,592,  "SVGA"},
	{CAPTURE_SIZE_XVGA,1024,768, "XVGA"},	
	{CAPTURE_SIZE_WXGA,1280,800, "WXGA"},	
	{CAPTURE_SIZE_SXGA,1280,1024,"SXGA"},
	{CAPTURE_SIZE_WSXGA,1600,1024,"SXGA"},	
	{CAPTURE_SIZE_UXGA,1600,1200,"UXGA"},		
	{CAPTURE_SIZE_WUXGA,1920,1200,"WUXGA"},	
	{CAPTURE_SIZE_LTF,240,192, "LTF"},
	{CAPTURE_SIZE_720p,1280,720,"720P"},
	{CAPTURE_SIZE_1_3M,1280,720,"960P"},
	{CAPTURE_SIZE_1080p,1920,1080,"1080P"},
	{CAPTURE_SIZE_3M,2048,1536,	"3M"},
	{CAPTURE_SIZE_5M,2560,1920,	"5M"},	
	{CAPTURE_SIZE_NR,0,0,NULL}
};

int ReslutionDH2Local(enum capture_size_t reslution,int *width,int *height)
{
	int i = 0;
	for(i =0;resolutionDef[i].res != CAPTURE_SIZE_NR; i++){
		if( reslution == resolutionDef[i].res){
			*width = resolutionDef[i].width;
			*height = resolutionDef[i].height;
			return KEY_TRUE;
		}	
	}
	return KEY_FALSE;
}


char *ReslutionNameLocal2DH(int width,int height)
{
	int i = 0;
	for(i =0;resolutionDef[i].res != CAPTURE_SIZE_NR; i++){
		if(resolutionDef[i].width == width && resolutionDef[i].height == height){ 
			return resolutionDef[i].name;
		}	
	}
	return NULL;
}

int DHGetResolutionCab(int height,int stream,char *Resolution[])
{
	int i = 0;
	switch(height)
	{
		case 1944:
			if(stream == 0)
			{
				Resolution[i++] = (char*)"5M";
			}
		case 1920:
			if(stream == 0)
			{
				Resolution[i++] = (char*)"5M";
			}
		case 1520:
			if(stream == 0)
			{
				Resolution[i++] = (char*)"2592*1520";
			}
		case 1536:
			if(stream == 0)
			{
				Resolution[i++] = (char*)"2048*1536";
			}
		case 1200:
			if(stream == 0)
			{
				Resolution[i++] = (char*)"1600*1200";
			}
		case 1080:
			if(stream == 0)
				Resolution[i++] = (char*)"1080P";
		case 960:
			if(stream == 0)
				Resolution[i++] = (char*)"1_3M";
		case 720:
			if(stream == 0)
				Resolution[i++] = (char*)"720P";
		case 576:		
			if((height >= 576)&&(stream == 0))
				Resolution[i++] = (char*)"D1";
		case 240:
			Resolution[i++] = (char*)"CIF";
		case 144:
			Resolution[i++] = (char*)"QCIF";
			break;
		default:
			printf("unknown ResolutionMask,need to be supported!\n");
			break;
	} 
	return i;
}